Release 10.1A: OpenEdge Development:
Progress Dynamics Basic Development


Calculated field support

Dynamic SmartDataObjects (and dynamic viewers) support calculated fields. When you add a calculated field to a dynamic SDO with the Calculated Field button, you can set the following attributes with the column editor: Name, Label, DataType, Format, and Help.

Note: A CalculatedField class extends the DataField class to support placement of calculated fields onto dynamic SDOs and dynamic viewers. This class should not be used and is not supported for any purpose other than calculated fields. Dynamic SDOs support calculated fields by invoking a function that follows a specific naming convention to calculate the values.

The Name attribute must be the same as the calculatedField object filename. You cannot specify an expression for the calculated field; therefore the framework disables the Edit button. You must write code to calculate the value for the field in a function of the dynamic SDO's data logic procedure and then name the function according to the required naming convention. The dynamic SDO invokes the function at run time to get the calculated value into its temp-table.

The framework creates a master calculatedField object in the Repository for each calculated field added to a dynamic SDO. If a master calculatedField already exists in the Repository, the framework raises an error and you must change the name of that calculated field in the SDO. The calculatedField master object has the same product module as the SDO. Master calculated fields cannot be reused on dynamic SDOs. You can create a calculatedField instance object for the dynamic SDO in the same way as you create a DataField instance object.

Calculated field functions

Dynamic SDO calculated fields must have functions defined in the SDO’s logic procedure called “Calculate” plus the field name. For example, a function called CalculateNewLimit is required in the data logic procedure to calculate the value for a calculated field called NewLimit. The function does not have access to the RowObject buffer and needs to make appropriate calls to the SDO to access the buffer if it requires information from the buffer for the calculation. A function to calculate the NewLimit in the data logic procedure might look like the following example:

FUNCTION CalculateNewLimit RETURNS DECIMAL: 
DEFINE VARIABLE hRowObject AS HANDLE NO-UNDO. 
DEFINE VARIABLE hCreditLimit AS HANDLE NO-UNDO. 
   hRowObject  = DYNAMIC-FUNCTION('getRowObject':U IN TARGET-PROCEDURE). 
   hCreditLimit = hRowObject:BUFFER-FIELD('CreditLimit':U). 
   RETURN hCreditLimit:BUFFER-VALUE * 1.10. 
END FUNCTION. 

Dynamic Viewer calculated fields

You can add calculated fields from static or dynamic SDOs as instances onto dynamic viewers. When you create a dynamic viewer with a static SDO as its data source, a calculatedField master object might not exist for calculated fields of that SDO. When this occurs, the framework creates master calculatedField objects for the calculated fields and sets their product modules to that of the dynamic viewer.

Saving static SDOs with calculated fields as dynamic SDOs

When you save a static SDO that contains calculated fields as a dynamic SDO, the framework creates master calculatedField objects for your calculated fields and saves them in the dynamic SDO. The names of these calculated fields must be unique within the Repository. To complete the change over to a dynamic SDO, you must move the expressions for the calculated fields to calculation functions in the dynamic SDO’s data logic procedure and edit the code as necessary.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095